Now that I have a minefield sign, let's go ahead and create a minefield.
I'm going to use code to populate the minefield by randomly putting mines around the sign.
Let's go to our workspace.
Hit the plus, add a folder and I'm going to call this mines.
So when I clone and spawn a mine, I'm going to put it in this folder so I can keep track so I know
how many there are going to be.
All right.
Now I'm going to go down to my server storage.
I'm going to look at the landmine.
We did this earlier in the course and I have a few things in the landmine model.
You can open and shut it right here.
I want to select a primary part from my landmine because I'm moving it with code, so I'm going to go
down to primary part, click here in the box to the right of where it says primary part, select a primary
part.
You used to have to do that or you get an error when you tried to move it with code using the move to.
Now, I think it's selects a random one if you don't do that.
But I like to know what the primary part is.
All right, now let's go to server script service.
Open up our session utils in session utils.
Let's get a reference to our minds folder.
I'll make a variable local.
I'll just call it with notes.
Mine folder, workspace mines.
Also, I want to know where that sign is and then put the minds close to the sign.
Right.
That's the whole point of having a sign for a minefield.
So I just need the sign position.
I don't really need the sign.
I'm going to need to get the sign for the position, though.
So I'll say Workspace landmine sign.
I'm going to get the post because that's the part that sticks in the ground.
I say position.
Cool.
One more variable local is a debris gain.
Get service debris.
What does this do?
This marks things with a time to live.
I'm going to be cloning minds, so I'm going to give them a time to live.
Let's say 5 to 10 minutes or something.
They'll disappear and then we'll put a new mine down, keep some randomness in our minefield.
Under my start wave.
I'm going to make a function to place my mines in the mine field.
I'm not going to say local.
I'm just going to start with function because I'm going to call this from my wave loop and I'll need
that utils prepend in place minds.
I'm going to pass in my desired number of mines.
None of mine's I'll move my mouse so you can see.
And then the distance is going to be the distance from the sign.
So basically how big my mind field is going to be, I'm going to need a variable for my mind.
It's internet and server storage.
I'm going to call this TX mine for template mine server storage.
That's the variable for server storage as wait for child landmine.
Now I also want the count.
I want to know how many minds I have in my mind folder at any given time.
We're going to start out with zero, but at some point we might have like five.
Maybe we want to have like ten.
So we need to keep track.
So we'll say count equals the number of mine folder.
Get children elements, right?
So there's five mines in our folder, count will be five.
I'm going to do a for loop for I equals count plus one up to the number of mines and steps of one.
Right.
So if we have five mines but we want ten, this is going to start out at six and it's going to go to
ten.
So we'll do five loops.
We're going to clone five new mines.
We need the location of where we're going to put those mines.
I'm going to do some random number generation.
So X rand, we have a random number generator called R and D, we'll say next int minus dist to dist.
So if this is 5050 studs, it's going to give you a number between -50 and 50.
We're going to do another one.
Woops, there we go for the Z z rand rand next integer minus dist to dest.
Cool.
Now the Y, I'm just going to use the Y from my TX mine.
So we are assuming a flat ground.
If you have complex terrain, then you're going to have to find out what your y value is.
You might even have to do something like in the spawn zombies and make spawn locations for your mines.
I'm just showing you a different way here.
So now what I'm going to do is I'm going to get a position that's going to have the three numbers that
I want.
I'm going to put this in a vector three.
You have to do a vector three new.
I'm going to have my x rand, but I'm going to use my sign position dot x plus my x rand value to my
TX mine.
We have a plate.
That's the primary part.
The plate has a position, the position has a y value.
So that's where I got my Y from, from the template.
Then I'm going to get my sign position Z plus z.
Oops, that's an x z.
Oh my gosh.
Z rand.
Who dies a lot.
I know that was kind of tricky.
So I put this on a new line just so you can see it.
You can keep it all on one line.
There we go.
So if you get like your minds in a line or something, you're going to know that you messed up one of
these, right?
Start checking out that stuff.
All right.
So we've got our position.
We still haven't cloned our mind.
So let's go ahead and make a variable called mine.
We'll get our TX mine will clone it.
Let me move this up so you can see it.
And then the mine's parent is going to be the folder, right?
The mine folder.
We want to put the mine in the mine folder.
That's how you do it.
You make the parent the mine folder.
We are going to move.
We'll do a move to on the model level possession.
This is the line that used to mess up.
If you didn't have a primary part assigned, I'm pretty sure they fixed it.
I don't know because I always assign a primary part if I use my move to All right, now we need our
debris service and we're going to add an item which is going to be the mine and give it a variable time
to live.
So I'll do a random next integer.
I'm going to give it a time to live between 3 minutes, which is 120 seconds and 5 minutes.
Right.
So after 5 minutes, definitely we know this mine's going to disappear, but that's okay.
Wave loop is going to be calling this and replacing mines when we need them.
Now let's go to our wave loop and call place mines.
So in service, script service, we have this wave loop running and underneath above the zombies, because
the zombies take a little bit of time, but below start wave, I'm going to get this, I'm going to
call a utils place mines.
We're going to need the number of mines, but we don't have that variable yet, so it's going to look
like an error and then we're going to have the distance from the sign distance from sign, right?
So we have two errors here.
We need to declare these variables as local number of mines.
How many mines should we give it?
Oh, 15, maybe 20, maybe let's do 15.
And then distance from sign, we'll save 50 studs.
Let's see what that looks like.
I'm going to put a weight underneath here, too, just to slow my loop down a little bit.
Yeah.
And we'll go to our world.
We'll do a play from here.
Let's go to home.
Play here.
All right, let's get our view output.
Pretty good.
We got some mines going.
We have a print statement in there.
Checking to see what the surface is.
Let's see if these things work.
Look at our zombies are stacking.
You should check that out.
Boom.
Cool beans.
We got.
We got a minefield.
Let's take a look at what it looks like in here.
So we should have, what, 15 of these?
And they'll replace as needed.
They're also going to disappear after a certain period of time and then be replaced so you can get your
zombies to come running through here.
That'd be pretty cool.